|
|
|
|
|
|
|
Figure 17.15
Program VBRay displaying 40 polygons and a sphere. |
|
|
|
|
|
|
|
|
Figure 17.15 shows program VBRay displaying a scene containing 40 RayPolygon objects surrounding a sphere. |
|
|
|
|
|
|
|
|
The RayDisk and RayPolygon classes represent shapes that lie in a plane. To see if a ray intersects their shapes, these classes first find the intersection between the ray and their planes. They then use different methods to decide whether the point on the plane lies within their shapes. |
|
|
|
|
|
|
|
|
You can extend this to manage other, possibly more complex, planar shapes. For example, you could use a similar technique to implement concentric rings or multiple polygons on the same plane. |
|
|
|
|
|
|
|
|
The RayCheckerboard class manages a checkerboard pattern. You define a checkerboard with the point at the corner of the checkerboard and two vectors used to generate its rectangular areas. The point and vectors define a plane much as a point and normal vector do. If the point has coordinates (px, py, pz), and the vectors are <v1x, v1y, v1z> and <v2x, v2y, v2z>, you can find the points on the plane using the parametric equations: |
|
|
|
 |
|
|
|
|
X(t, u) = px + i * v1x + j * v2x
Y(t, u) = py + i * v1y + j * v2y
Z(t, u) = pz + i * v1z + j * v2z |
|
|
|
|
|
|
|
|
where the values i and j vary over the real numbers. |
|
|
|
|
|
|
|
|
The RayCheckerboard class also takes two parameters, NumSquares1 and NumSquares2, that tell it how to restrict the area on this plane. To find the corners of the checkerboard squares, the class uses integer values for i and j where: |
|
|
|
 |
|
|
|
|
0 <= i <= NumSquares1
0 <= j <= NumSquares2 |
|
|
|
|
|